package com.demo.service.impl;

import com.demo.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.demo.mapper.SysMenuMapper;
import com.demo.domain.SysMenu;
import com.demo.service.SysMenuService;



@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService{

    /**
     * 角色查询接口
     */
    @Autowired
    private SysRoleService sysRoleService;

    @Autowired
    private SysMenuMapper sysMenuMapper;



    /**
     * 根据 用户id 查询菜单
     * @param userId
     * @return
     */
    @Override
    public List<SysMenu> getMenusByUserId(Long userId) {
        //1.如果该用户是超级管理员 -》 拥有所有菜单
        if(sysRoleService.isSuperAdmin(userId)){
            return list();
        }
        //2.如果不是超级管理员 ->查询角色 根据角色查询菜单
        return sysMenuMapper.selectMenusByUserId(userId);
    }


}
